#coding:utf8

from common import *

import subprocess as sp

def start(conf):
	argv=conf['argv']
	pwd, app=splitdir(argv[0])
	if not pwd: pwd='.'
	# print 'app=', app
	# print 'pwd=', pwd
	argc=len(argv)
	if argc==1:
		for name, dp in dirs.items():
			if not exists(dp): md(dp)
		num_fechers=10
		try: num_fechers=conf['num_fechers']
		except: pass
		sp.Popen(r'python %s parser' % app, cwd=pwd)
		for i in range(num_fechers):
			sp.Popen('python %s fecher %d %d' % (app, num_fechers, i), cwd=pwd)
	elif argc==2:
		import pageparser
		pageparser.start(conf)
	elif argc==4:
		import webfetcher
		nfs=int(argv[2])
		fid=int(argv[3])
		webfetcher.start(conf, nfs, fid)
	
if __name__=='__main__':
	pass
	

